//
//  Fliper.h
//  yuikemall
//
//  Created by yuike6 yuike6 on 12-2-17.
//  Copyright (c) 2012年 yuike. All rights reserved.
//

/* 
    此类为基类，不可直接使用。
 */

#import "UIViewEx.h"


typedef enum {
	YFlipperDirectionLeft,
	YFlipperDirectionRight,
    YFlipperDirectionUp,
    YFlipperDirectionRDown
} YFlipperDirection;


typedef enum{
    kFLIPER_STYLE_FOLDOVER = 1,
    kFLIPER_STYLE_PULL,
    
    kFliperStyleCount
} FliperStyle;


@protocol FliperDataSource;
@protocol FliperDelegate;

@interface Fliper : UIViewEx<UIGestureRecognizerDelegate>
{
    id<FliperDelegate> delegate_;
    NSObject<FliperDataSource > *    datasource_;
    BOOL animating;
    
    UIView * current_view_;
    UIView * next_view_;
    
    NSInteger currentPage;
	NSInteger numberOfPages;
    
    YFlipperDirection flipDirection;
    
    CGFloat * beginPoint_x;
    
    NSMutableArray * skipGestureClasses_;
    
    UIPanGestureRecognizer *panRecognizer_;
    UITapGestureRecognizer * tapRecognizer_;
    
    float translation;	
	float progress;
    float lastProgress;
    CGPoint velocity;
    
    NSInteger oldPage;
    BOOL hasFailed;
    
    BOOL initialized;
    BOOL bSkipGesture;
    
    BOOL setNextViewOnCompletion;
    
    BOOL canRotate;
    
    BOOL autoFliper;
    
    BOOL canNotFliper;
    
}
@property (nonatomic, assign) id<FliperDelegate> delegate;
@property (nonatomic, assign) id<FliperDataSource >   dataSource;
@property (readonly, nonatomic, getter=isAnimating) BOOL animating;

@property (nonatomic, retain) UIView * currentView;
@property (nonatomic, retain) UIView * nextView;

@property (nonatomic,assign) NSInteger currentPage;
@property (nonatomic, assign) NSInteger numberOfPages;
@property (nonatomic, assign) YFlipperDirection flipDirection;

@property (nonatomic, readonly, retain) NSMutableArray * skipGestureClasses;

@property (nonatomic, retain) UIPanGestureRecognizer *panRecognizer;
@property (nonatomic, retain) UITapGestureRecognizer * tapRecognizer;
@property (nonatomic, assign) BOOL canRotate;

@property (nonatomic, assign) BOOL autoFliper;
@property (nonatomic, assign) BOOL canNotFliper;

/* 需要重写的方法*/
- (void) flipeBegin     : (UIPanGestureRecognizer *) recognizer;
- (void) flipeMove      : (UIPanGestureRecognizer *) recognizer;
- (void) flipeEnd       : (UIPanGestureRecognizer *)recognizer;
- (void) flipeFailed    : (UIPanGestureRecognizer *)recognizer;
- (void) flipeCanceled  : (UIPanGestureRecognizer *)recognizer;
- (void) tapGesture     : (UITapGestureRecognizer *) recognizer; 

- (void) setCurrentPageIndexEx:(NSInteger) currectPageIndexValue;
- (void) setCurrentPageIndexEx:(NSInteger) value animated:(BOOL) animated;
- (BOOL) doSetCurrentPageEx:(NSInteger) value;

// 翻页到第一页了
- (BOOL) flipFirstPage;

// 翻页到最后一页了
- (BOOL) flipLastPage;

-(void) setNumberOfPages:(NSInteger)numberOfPages WithNilPage:(BOOL) ishas;

// 给外部一个可以 界面 和 数据的接口，至于做什么事情，由具体的子类决定
-(void) refresh;

/* == */
- (void) registeSkipGestureClass:(Class) aClass;
//- (void) fliperPageByPageIndex:(NSInteger) pageindex;
- (BOOL) doSetCurrentPage:(NSInteger) value;
- (BOOL) doSetCurrentPage:(NSInteger) value force:(BOOL) force;
- (void) setCurrentPage:(NSInteger) value animated:(BOOL) animated;

- (void) setCurrentPage:(NSInteger) value animated:(BOOL) animated force:(BOOL) force;
- (void) setCurrentPage:(NSInteger) value force:(BOOL) force;
- (BOOL) doSetCurrentPage:(NSInteger) value force:(BOOL) force;

@end



@protocol FliperDataSource <NSObject>

// get page count
- (NSInteger) numberOfPagesForPageFlipper:(Fliper *) fliper;
- (UIView *) viewForPage:(NSInteger) page 
                   inFlipper:(Fliper *) fliper ;

@end

@protocol FliperDelegate <NSObject>
@optional
- (void) fliperView:(Fliper *)leavesView willTurnToPageAtIndex:(NSUInteger)pageIndex;
- (void) fliperView:(Fliper *)leavesView didTurnToPageAtIndex:(NSUInteger)pageIndex;
- (void) fliperView:(Fliper *)leavesView zoomingCurrentView:(NSUInteger)zoomLevel;
- (void) fliperView:(Fliper *)leavesView doubleTapCurrentView:(NSUInteger)fooVariable;

@end